"""
Case Type   : 系统表
Case Name   : 测试系统表PG_AM字段与数据类型
Create At   : 2021/10/12
Owner       : lvlintao666
Description :
    1.查看系统表PG_AM的表结构
    2.该表字段与对应字段数据类型是否正确
Expect      :
    1.查看系统表PG_AM的表结构成功
    2.该表字段与字段数据类型对应正确
History     :
    modified：2024/12/9 by 30044860 优化用例，开发代码变更
"""

import sys
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH

logger = Logger()


class IndexFileDamaged(unittest.TestCase):
    def setUp(self):
        logger.info('----------------this is setup-----------------------')
        logger.info('--------------Opengauss_Function_System_Table_Case0008开始执行--------------')
        self.userNode = Node('dbuser')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.com = Common()
        self.comsh = CommonSH('dbuser')
        self.expect_result_dict = {
            'Column': ['amname', 'amstrategies', 'amsupport', 'amcanorder', 'amcanorderbyop', 'amcanbackward',
                       'amcanunique', 'amcanmulticol', 'amoptionalkey', 'amsearcharray', 'amsearchnulls', 'amstorage',
                       'amclusterable', 'ampredlocks', 'amkeytype', 'aminsert', 'ambeginscan', 'amgettuple',
                       'amgetbitmap', 'amrescan', 'amendscan', 'ammarkpos', 'amrestrpos', 'ammerge', 'ambuild',
                       'ambuildempty', 'ambulkdelete', 'amvacuumcleanup', 'amcanreturn', 'amcostestimate', 'amoptions',
                       'amhandler', 'amdelete'],
            'Type': ['name', 'smallint', 'smallint', 'boolean', 'boolean', 'boolean', 'boolean', 'boolean', 'boolean',
                     'boolean', 'boolean', 'boolean', 'boolean', 'boolean', 'oid', 'regproc', 'regproc', 'regproc',
                     'regproc', 'regproc', 'regproc', 'regproc', 'regproc', 'regproc', 'regproc', 'regproc', 'regproc',
                     'regproc', 'regproc', 'regproc', 'regproc', 'regproc', 'regproc']}

    def test_Index_file_damaged(self):
        logger.info('----------------------------查看表结构-----------------------------')
        msg = self.comsh.execut_db_sql('\d PG_AM')
        logger.info(msg)
        result_dict = self.com.format_sql_result(msg)
        logger.info(result_dict)
        del result_dict['Modifiers']
        self.assertDictEqual(self.expect_result_dict, result_dict)

    def tearDown(self):
        logger.info('----------------this is tearDown-----------------------')
        # 无须清理环境
        logger.info('-----------------Opengauss_Function_System_Table_Case0008执行完成--------------------')
